﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication1
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string name = TextBox1.Text;
            string pwd = TextBox2.Text;

            string server = "server = .;uid = Sa;pwd = 123456; database = Student";

            SqlConnection sqlcon = new SqlConnection(server);

            sqlcon.Open();

            string sql = "select * from StudenInfo where stuName = @name and  password = @pwd";

            SqlParameter[] pras =
            {
                new SqlParameter("@name",name),
                new SqlParameter(" @pwd" ,pwd),

            };

            SqlCommand sqlC = new SqlCommand(sql, sqlcon);

            if (pras!= null)
            {
                sqlC.Parameters.AddRange(pras);
            }
            SqlDataReader sqlData = sqlC.ExecuteReader();
            if (sqlData.Read())
            {
                Session["CurrenUsername"] = name;
                Label1.Text = "登录成功";
            }
            else
            {
                Label1.Text = "登录失败";
            }

        }
    }
}